import 'package:ca_dsp_pro/src/common/bg_chart.dart';
import 'package:ca_dsp_pro/src/common/unit_tool.dart';
import 'package:ca_dsp_pro/src/modules/eq/my_eq_controller.dart';
import 'package:ca_dsp_pro/src/tool/assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class MyEq extends EqPageDelegate<MyEqController> {
  BoxDecoration decoration(Color color) {
    return BoxDecoration(
      color: color,
      borderRadius: BorderRadius.circular(5),
      border: BoxBorder.all(color: Color_bg_view, width: 0.3),
      boxShadow: [
        BoxShadow(color: Color_bg_view2.withAlpha(100), offset: const Offset(0, 0), blurRadius: 2, spreadRadius: 2)
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color_bg_view,
      child: Row(children: [
        Expanded(
            child: Column(
          spacing: 5,
          children: [
            Expanded(child: BgChart()),
            SizedBox(
              height: 60,
              child: Obx(() {
                return UnitTool(
                    chlist: globalController.rxModel.value.ch_list,
                    grouplist: controller.groupList,
                    onTouch: (ch) => controller.chooseChInGroup(ch),
                    onLink: (index) => controller.chooseGroup(index));
              }),
            )
          ],
        )),
        SizedBox(
            width: 60,
            child: Container(
              padding: const EdgeInsets.only(top: 5, bottom: 5, left: 10, right: 10),
              child: Column(
                spacing: 5,
                children: List.generate(3, (index) {
                  if (index == 2) {
                    return Obx(() {
                      final text = globalController.byPassStatus.value == EQBypassStatus.restore ? 'BYPASS' : 'RESTORE';
                      return Container(
                        height: 55,
                        // decoration: decoration(Color_bg_view2),
                        child: Material(
                          color: Color_bg_view2,
                          borderRadius: BorderRadius.circular(5),
                          child: InkWell(
                            borderRadius: BorderRadius.circular(5),
                            onTap: () => globalController.bypassEQ(),
                            child: Center(
                              child: FittedBox(
                                fit: BoxFit.scaleDown,
                                child: Text(text, style: TextStyle(fontSize: 18)),
                              ),
                            ),
                          ),
                        ),
                      );
                    });
                  } else {
                    return Obx(() {
                      final select1 = index == 0 && controller.add_touch.value;
                      final select2 = index == 1 && controller.sub_touch.value;
                      final Color color1 = select1 ? Colors.blue : Colors.red;
                      final Color color2 = select2 ? Colors.blue : Colors.red;
                      return Expanded(
                        child: LongPressRepeatDetector(
                          interval: Duration(milliseconds: 30),
                          child: Container(
                            decoration: decoration(index == 0 ? color1 : color2),
                            child: Center(
                              child: Image.asset(index == 0 ? assets.add : assets.sub, width: 30, height: 30),
                            ),
                          ),
                          onPressEnd: () => controller.touchAddSub(index, false),
                          onPressStart: () => controller.touchAddSub(index, true),
                          onPress: () {
                            controller.touchAddSub(index, true);
                            controller.updateSignGain(index == 0);
                          },
                        ),
                      );
                    });
                  }
                }),
              ),
            ))
      ]),
    );
  }
}
